package com.infolab.aims.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.validator.constraints.NotBlank;
import com.infolab.aims.common.SpecialToStringStyle;
import com.infolab.aims.common.bean.AbstractModelBean;

@Entity
@Table(name = "AMTB_LOCATION")
public class Location extends AbstractModelBean implements Serializable {

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer locationId;

	@NotBlank(message = "{error.empty}")
	private String locationCode;

	@NotBlank(message = "{error.empty}")
	private String locationName;

	@Column(columnDefinition = "number(1,0) default 1 not null")
	private boolean active;

	@ManyToOne
	@JoinColumn(name = "sectionId")
	@NotNull(message = "{error.empty}")
	private Section section;

	private String sort;

	public Integer getLocationId() {
		return locationId;
	}

	public void setLocationId(Integer locationId) {
		this.locationId = locationId;
	}

	public String getLocationCode() {
		return locationCode;
	}

	public void setLocationCode(String locationCode) {
		this.locationCode = locationCode;
	}

	public String getLocationName() {
		return locationName;
	}

	public void setLocationName(String locationName) {
		this.locationName = locationName;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public Section getSection() {
		return section;
	}

	public void setSection(Section section) {
		this.section = section;
	}

	public String getAuditContentHead() {
		Section sec = section != null ? section : new Section();

		return new ToStringBuilder(this, SpecialToStringStyle.SPECIAL_STYLE).append("Location Code", locationCode)
				.append("Location Name", locationName).append("Section", sec.getSectionCode() + "-" + sec.getSectionName()).toString();
	}

	public String getAuditContentDetail() {
		return super.getAuditContentDetail();
	}

	public String getAuditCode() {
		if (StringUtils.isNotEmpty(locationCode)) {
			return locationCode;
		}
		return super.getAuditCode();
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

}
